Use relative-time to render absolute dates#36238
Conversation
wxiaoguang
left a comment
There was a problem hiding this comment.
I have strong objection of using "go-snaps" to update test data automatically.
|
Why object snapshot testing? It's clearly superior than tediously manually writing expected strings. I've given up on a number of PRs because it's too much work to to manually write out expected HTML. Take a look at repos like https://github.com/microsoft/typescript-go, 90% of their tests are snapshot-based. It's a huge DX improvement having the ability to "auto update" tests. |
Because many Gitea maintainers are too lazy to write correct tests, not that experienced as typescript-go developers. But I won't insist, feel free to dismiss my change request if you believe we need it. |
|
I think both regular and snapshot tests have their uses. Let's say I want to add another attribute, I need to manually update 6 assertions vs. running this and be done with it: BTW there is nothing preventing you from editing the snapshot assertion string, so the string can be updated either manually (if you prefer), or automatically. |
* origin/main: (152 commits) Fine tune diff highlighting (go-gitea#36592) Add code editor setting dropdowns (go-gitea#36534) Update to go 1.26.0 and golangci-lint 2.9.0 (go-gitea#36588) Improve diff highlighting (go-gitea#36583) Fix markup code block layout (go-gitea#36578) Remove striped tables in UI (go-gitea#36509) Fix vertical alignment of `.commit-sign-badge` children (go-gitea#36570) Fix mirror sync parser and fix mirror messages (go-gitea#36504) Update JS and PY deps (go-gitea#36576) Add viewer controller for mermaid (zoom, drag) (go-gitea#36557) Misc typescript tweaks (go-gitea#36523) Use full-file highlighting for diff sections (go-gitea#36561) fix(diff): reprocess htmx content after loading more files (go-gitea#36568) [skip ci] Updated translations via Crowdin Add wrap to runner label list (go-gitea#36565) fix: add dnf5 command for Fedora in RPM package instructions (go-gitea#36527) Enable pagination on GiteaDownloader.getIssueReactions() (go-gitea#36549) Refactor merge conan and container auth preserve actions taskID (go-gitea#36560) Fix assignee sidebar links and empty placeholder after go-gitea#32465 refactor (go-gitea#36559) Fix various version parsing problems (go-gitea#36553) ...
Replace `snaps.MatchInlineSnapshot` calls with `assert.EqualValues` in date utility tests, removing the github.com/gkampitakis/go-snaps dependency and its transitive dependencies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Reverted to static assertions. I guess I will offload such menial task like test assertion updates to agents now, but it's still a waste of agent time when I could have just run a command to update them instantly. But whatever makes you happy. |
There was a problem hiding this comment.
Pull request overview
This PR replaces the project’s custom <absolute-date> web component with @github/relative-time-element configured to render absolute dates (via threshold="P0Y" and prefix=""), aligning date rendering on a single component.
Changes:
- Remove the
<absolute-date>web component (and its unit test) and stop registering it in the frontend build. - Update Go template date helpers/tests to emit
<relative-time>for “absolute short” date rendering. - Update the devtest UI template to demonstrate absolute date rendering via
<relative-time>.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
webpack.config.ts |
Removes absolute-date from the custom-elements allowlist for Vue compilation. |
web_src/js/webcomponents/index.ts |
Stops importing/initializing the absolute-date web component. |
web_src/js/webcomponents/absolute-date.ts |
Deletes the custom absolute date web component implementation. |
web_src/js/webcomponents/absolute-date.test.ts |
Deletes tests for the removed absolute date helper. |
templates/devtest/gitea-ui.tmpl |
Updates devtest examples to use <relative-time> for absolute dates. |
modules/templates/util_date.go |
Switches “date-only” rendering from <absolute-date> to <relative-time> with absolute-date configuration. |
modules/templates/util_date_test.go |
Updates expected HTML strings to match the new <relative-time> output for absolute dates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: silverwind <me@silverwind.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@wxiaoguang still blocking? |
Suggested by lunny https://discord.com/channels/322538954119184384/323701541297192961/1472491165004726345
And we might could enable the feature that dissmissing all the previous reviews once a new commit pushed after it was approved or rejected.
This PR gets new changes after approval.
`<relative-time>` can render absolute dates when passed [`threshold="P0Y"`](https://github.com/github/relative-time-element#threshold-string-default-p30d) and `prefix=""`, so remove the previously used `<absolute-date>` element in its favor. Devtest before: <img width="324" height="210" alt="Screenshot 2025-12-23 at 20 22 44" src="https://github.com/user-attachments/assets/cf78e0e7-f480-415f-98d5-09b25f9d5a8b" /> Devtest after: <img width="274" height="184" alt="Screenshot 2025-12-23 at 20 22 49" src="https://github.com/user-attachments/assets/5e7d25f6-eea1-4a8c-ba71-02b570804b95" /> Repo activity (rendering unchanged): <img width="1023" height="67" alt="image" src="https://github.com/user-attachments/assets/2c4fd6cb-14ab-43c6-ae4b-f86946b28288" /> --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
<relative-time>can render absolute dates when passedthreshold="P0Y"andprefix="", so remove the previously used<absolute-date>element in its favor.Devtest before:
Devtest after:
Repo activity (rendering unchanged):